package com.endoc.news.fragment.homefragment;

import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

import com.endoc.news.application.NewsApplication;
import com.endoc.news.fragment.base.BaseMvvmModel;
import com.endoc.news.fragment.base.BaseMvvmViewModel;
import com.endoc.news.fragment.mvvm.model.IBaseModelListener;
import com.endoc.news.fragment.mvvm.model.PagingResult;
import com.endoc.news.netWoke.bean.NewsChannelsBean;
import com.orhanobut.logger.Logger;

import java.util.List;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;

//implements IBaseModelListener<List<NewsChannelsBean.ChannelList>>
public class HomeFragmentViewModel extends BaseMvvmViewModel<NewsChannelsBeanModel,NewsChannelsBean.ChannelList>{
    //NewsChannelsBeanModel mNewsChannelsBeanModel;
   //MutableLiveData<List<NewsChannelsBean.ChannelList>> mListMutableLiveData;
    public HomeFragmentViewModel() {
        //mNewsChannelsBeanModel = new NewsChannelsBeanModel();
        //mListMutableLiveData =new MutableLiveData<List<NewsChannelsBean.ChannelList>>();
        //mNewsChannelsBeanModel.registerModelListener(this);
        //mNewsChannelsBeanModel.getCacheData();
    }
 public static class HomeFragmentViewModelFactory implements  ViewModelProvider.Factory {
        @NonNull
        @Override
        public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
            return (T)new HomeFragmentViewModel();
        }
    }


    @Override
    public NewsChannelsBeanModel createModel() {
        return new NewsChannelsBeanModel();
    }

  /*  @Override
    public void success(BaseMvvmModel baseMvvmModel, List<NewsChannelsBean.ChannelList> t, PagingResult... pagingResults) {
        if(baseMvvmModel instanceof NewsChannelsBeanModel){//viewModel中可能存在多个model,所以判断再去进行操作
            mListMutableLiveData.postValue(t);
        }
        //homeFragmentAdapter.setData(t);
    }

    @Override
    public void fail(BaseMvvmModel baseMvvmModel, Throwable e, PagingResult... pagingResults) {
        //Logger.d("onError===" + e);
        Toast.makeText(NewsApplication.mNewsApplication.getBaseContext(),"请求失败",Toast.LENGTH_SHORT).show();
    }*/

}
